package netWork.练习1_聊天室.多客户端实现;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

/**
 * @Package netWork.练习1_聊天室.多客户端实现
 * @Author shimmer
 * @Date 2020/8/4 12:54
 * @TODO
 */
public class CloseUtil {
    DataOutputStream os;
    DataInputStream is;
    Socket socket;
    Scanner scanner;
    ServerSocket serverSocket;

    public CloseUtil(DataInputStream is, DataOutputStream os, Scanner scanner, Socket socket) {
        this.is = is;
        this.os = os;
        this.scanner = scanner;
        this.socket = socket;
    }
    
    public CloseUtil(Socket socket) {
        this.socket=socket;
    }


    public void close() {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (scanner != null) {
            scanner.close();
        }
        if (socket != null) {
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
